package com.gict.antifraudback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gict.antifraudback.entity.LikeRecord;
import com.gict.antifraudback.mapper.LikeRecordMapper;
import com.gict.antifraudback.service.LikeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author XIE
* @description 针对表【like_record】的数据库操作Service实现
* @createDate 2023-11-02 15:18:53
*/
@Service
public class LikeRecordServiceImpl extends ServiceImpl<LikeRecordMapper, LikeRecord>
    implements LikeRecordService{

    @Override
    public Integer countByArticleId(Integer id) {
        LambdaQueryWrapper<LikeRecord> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(LikeRecord::getTargetType, "article");
        wrapper.eq(LikeRecord::getTargetId, id);
        return count(wrapper);
    }

    @Override
    public List<LikeRecord> listByIdsAndType(List<Integer> ids, String type, Integer id) {
        LambdaQueryWrapper<LikeRecord> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(LikeRecord::getLikeType, 0);
        wrapper.eq(LikeRecord::getTargetType, type);
        wrapper.eq(LikeRecord::getUserId, id);
        wrapper.in(LikeRecord::getTargetId, ids);

        return list(wrapper);
    }

    @Override
    public Map<Integer, Map<String, Long>> countByArticleCommentIdsAndType(List<Integer> ids) {
        return this.baseMapper.countByArticleCommentIdsAndType(ids);
    }
}




